package com.sicheng.lc.周赛.分类.哈西表or计数or滑动窗口or双指针.滑动窗口;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/9/7 23:45
 */
public class 最长优雅子数组 {
    //https://leetcode.cn/problems/longest-nice-subarray/
    public int longestNiceSubarray(int[] nums) {
        int mask = 0;
        int max = 0;
        for (int r = 0, l = 0; r < nums.length; r++) {
            while ((nums[r] & mask) != 0) {
                mask ^= nums[l];
                l++;
            }
            mask |= nums[r];
            max = Math.max(max, r - l + 1);
        }
        return max;
    }
}
